<template>
<div>
  <el-table
    :data="parentPermission"
    style="width: 100%;margin-bottom: 20px;"
    row-key="id"
    border
    default-expand-all
    :tree-props="{children: 'children', hasChildren: 'hasChildren'}">
    <el-table-column
      prop="permissionName"
      label="上级权限名称"
      width="300px">
    </el-table-column>
    <el-table-column
      prop="url"
      label="上级权限路由"
      width="240px">
    </el-table-column>
    <el-table-column
      prop="roleNames"
      label="上级权限对应角色名称">
    </el-table-column>
    <el-table-column
      prop="adminUsernames"
      label="上级拥有该权限的管理员">
    </el-table-column>
  </el-table>
  <el-form ref="form" class="input" :model="permission" label-width="80px">
    <el-form-item label="权限名称">
      <el-input  v-model="permission.permissionName"></el-input>
    </el-form-item>
    <el-form-item label="权限路由">
      <el-input v-model="permission.url"></el-input>
    </el-form-item>
     <el-form-item>
        <el-button type="primary" @click="addPermission">立即创建</el-button>
        <router-link :to="'/permission/list'">
        <el-button >取消</el-button>
        </router-link>
      </el-form-item>
    </el-form>
</div>
</template>
<script>
  import permission from'@/api/permission/permission'
  export default {
    data() {
      return {
       parentPermission:[],
       permission:{},
       parentId:-1
    }
    },
    created() {
       if(this.$route.params && this.$route.params.id){
           this.parentId=this.$route.params.id
           this.getPermissionListById()
       }
    },
    methods: {
     // updateAdmin(){
     //   adminApi.updateAdmin(this.admin)
     //   .then(response=>{
     //     this.$message({
     //       type: 'success',
     //       message: '修改成功!'
     //     });
     //     this.$router.push({ path: '/admin/table' })
     //   })
     //   }
     // ,
     getPermissionListById(){
       permission.getPermissionListById(this.parentId)
       .then(response=>{
         this.parentPermission=response.data.parentPermission
       })
     },
     addPermission(){
       permission.addPermission(this.permission,this.parentId)
       .then(response=>{
         this.$message({
           type: 'success',
           message: '添加成功!'
         });
         this.$router.push({ path: '/permission/list' })
       })
     }
    }
  }
</script>
<style>
  .input{
    width: 600px;
  }
</style>
